package com.pervasa.demo.re.impl.data;

import com.pervasa.demo.re.impl.ReactivityEngine;

public class Rule {
	private String name;
	private Event event = null;
	private Action action = null;
	private Condition condition = null;

//	private ReactivityEngine env;

	public Rule(String ruleName, Event event, Condition condition,
			Action action, ReactivityEngine env) {
		this.name = ruleName;
		this.event = event;
		this.condition = condition;
		this.action = action;
//		this.env = env;
		event.addRuleListeners(this);
	}

	public void evaluate() {
		System.out.println("Rule Eval:" + name + ":" + event.isTriggered());
		if (event.isTriggered()) {
			// event has occured
			// check conditions here
			if (condition.getValue()) {
				// condition is true, trigger action
				action.execute();
			}
		}
	}

	public String toString() {
		return name + ": //" + event.getName() + ", " + condition.getName()
				+ ", " + action.getName() + "//";
	}
}